﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace MethodWorx.Core.DomainModel
{
    using Extensions;
    using System.ComponentModel.Design;

    public abstract class Repository<T> : IRepository<T>
        where T : AggregateRoot
    {
        public abstract IEnumerable<T> All();
        public abstract IQueryable<T> Query();
        public abstract T this[Guid id] { get; }
        public abstract bool Contains(T entity);
        public abstract void Delete(T entity);
        public abstract void Insert(T entity);
        public abstract void Update(T entity);

        public T CreateEntityInstance()
        {
            return this.OnCreateEntityInstance();
        }

        public virtual T OnCreateEntityInstance()
        {
            T result = Activator.CreateInstance<T>();
            return result;
        }

        void IRepository.Insert(object entity) { this.Insert((T)entity); }
        void IRepository.Update(object entity) { this.Update((T)entity); }
        void IRepository.Delete(object entity) { this.Delete((T)entity); }


        public virtual object CreateInstance(Type type)
        {
            return Activator.CreateInstance(type);
        }
    }

}
